/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.eventos.bc;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.cip.esymons.eventos.be.TipoEvento;

/**
 *
 * @author OscarA
 */
public class TipoEventoDelegate {

    TipoEventoFacadeLocal local;

    public TipoEventoDelegate() {
        local = lookupTipoEventoFacade();
    }

    private TipoEventoFacadeLocal lookupTipoEventoFacade() {
        try {
            Context c = new InitialContext();
            return (TipoEventoFacadeLocal) c.lookup("java:comp/env/TipoEventoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void guardar(TipoEvento tipo) {
        try {
            local.create(tipo);
        } catch (Exception e) {
            
        }
    }

    public void actualizar(TipoEvento tipo) {
        try {
            local.edit(tipo);
        } catch (Exception ex) {

        }
    }

    public List<TipoEvento> listar_Todos() {
        try {
            return local.findAll();
        } catch (Exception e) {
            return null;
        }
    }

    public TipoEvento buscarTipoEvento(Integer id) throws Exception {
        try {
            return local.find(id);
        } catch (Exception e) {
            local = lookupTipoEventoFacade();
            throw new Exception(e.getStackTrace().toString(), e);
        }
    }

    public TipoEvento findTipoEvento(Integer id) throws Exception {
        return local.find(id);
    }


}
